//************************************************************************
/// <copyrigth>2024-2025 Corporation.All Rights Reserved</copyrigth>
/// <author>tangyingzhong</author>
/// <contact>tangyz114987@outlook.com</contact>
/// <version>v1.0.0</version>
/// <describe>
/// You can inherit it to get the event notify power
/// Note:Your own interface must inherit the IBaseEvent
///</describe>
/// <date>2024/4/28</date>
///***********************************************************************
#ifndef EVENTBASE_H
#define EVENTBASE_H

#include "ModuleLoader/ModuleConfig.h"
#include "IBaseEvent.h"
#include "BaseEvent.h"

namespace SystemTool
{
    template <class T = IBaseEvent>
    class CLASS_ITEM EventBase : public T
    {
    public:
        // Constrcut the obj
        EventBase(){    }

        // Destruct the obj
        virtual ~EventBase(){    }
    
    private:
        // Copy construct
        EventBase(const EventBase &other) = delete;

        // Assignment
        EventBase& EventBase(const EventBase &other) = delete;

    public:
        // Register the event
        virtual void Register(int iEventId, std::function<void(EventArgs &)> fEventHandlerFunc)
        {
            m_BaseEvent.Register(iEventId, fEventHandlerFunc);
        }

        // Unregister the event
        virtual void UnRegister(int iEventId, std::function<void(EventArgs &)> fEventHandlerFunc)
        {
            m_BaseEvent.UnRegister(iEventId, fEventHandlerFunc);
        }

        // Notify the target
        virtual void Notify(EventArgs &Args)
        {
            Args.pSender = this;
            m_BaseEvent.Notify(Args);
        }

        // Asyn notify the event
        virtual void AsynNotify(EventArgs &Args, std::function<void(EventArgs &)> fResFunc = nullptr, long lTimeout_Ms = 60000)
        {
            Args.pSender = this;
            m_BaseEvent.AsynNotify(Args, fResFunc, lTimeout_Ms);
        }

    private:
        // Base event
        BaseEvent m_BaseEvent;
    };
}

#endif // EVENTBASE_H
